/**
 * 智慧社区管理系统 - 移动端员工管理API接口
 * @author Wu.Liang
 * @date 2025-01-30
 * @description 移动端工程位于smart-community-app文件夹，严格遵循架构总览中的项目结构规范
 */

import request from '@/api/request'

// 员工管理API
export const staffApi = {
  // 获取员工列表
  getStaffList: (params) => {
    return request.get('/api/work/staff/list', { params })
  },

  // 获取员工详情
  getStaffDetail: (staffId) => {
    return request.get(`/api/work/staff/${staffId}`)
  },

  // 添加员工
  addStaff: (data) => {
    return request.post('/api/work/staff', data)
  },

  // 更新员工信息
  updateStaff: (staffId, data) => {
    return request.put(`/api/work/staff/${staffId}`, data)
  },

  // 删除员工
  deleteStaff: (staffId) => {
    return request.delete(`/api/work/staff/${staffId}`)
  },

  // 搜索员工
  searchStaff: (keyword, status) => {
    return request.get('/api/work/staff/search', {
      params: { keyword, status }
    })
  },

  // 获取员工考勤记录
  getStaffAttendance: (staffId, params) => {
    return request.get(`/api/work/staff/${staffId}/attendance`, { params })
  },

  // 更新员工状态
  updateStaffStatus: (staffId, status) => {
    return request.put(`/api/work/staff/${staffId}/status`, { status })
  },

  // 上传员工头像
  uploadStaffAvatar: (file, staffId) => {
    return request.upload('/api/work/staff/avatar', file, 'file', { 
      staffId,
      uploadType: 'STAFF_AVATAR', 
      uploadSource: 'APP', 
      remark: '员工头像' 
    })
  },

  // 根据物业公司ID获取员工列表
  getStaffByPropertyCompany: (propertyCompanyId) => {
    return request.get(`/api/user/user/list/property/${propertyCompanyId}`)
  },

  // 根据物业公司ID获取按角色分组的用户列表
  getUsersByRoleGroup: (propertyCompanyId) => {
    return request.get(`/api/user/users/by-role-group/${propertyCompanyId}`)
  },

  // 新增物业公司用户 - 严格按照后端接口对接（移动端专用）
  addPropertyCompanyUser: (data) => {
    return request.post('/api/user/mobile/property-company/add', data)
  }
}

// 考勤管理API
export const attendanceApi = {
  // 获取考勤记录列表
  getAttendanceList: (params) => {
    return request.get('/api/work/attendance/list', { params })
  },

  // 员工签到
  checkIn: (data) => {
    return request.post('/api/work/attendance/checkin', data)
  },

  // 员工签退
  checkOut: (data) => {
    return request.post('/api/work/attendance/checkout', data)
  },

  // 获取考勤统计
  getAttendanceStats: (staffId, params) => {
    return request.get(`/api/work/attendance/stats/${staffId}`, { params })
  }
}

// 部门管理API
export const departmentApi = {
  // 获取部门列表
  getDepartmentList: () => {
    return request.get('/api/work/department/list')
  },

  // 获取职位列表
  getPositionList: (departmentId) => {
    return request.get('/api/work/position/list', {
      params: { departmentId }
    })
  }
}

// 角色管理API
export const roleApi = {
  // 获取所有启用的角色列表
  getEnabledRoles: () => {
    return request.get('/api/user/roles/enabled')
  },

  // 根据物业公司ID获取角色列表
  getRolesByPropertyCompany: (propertyCompanyId) => {
    return request.get('/api/user/roles/property', {
      params: { propertyCompanyId }
    })
  }
}

export default {
  staffApi,
  attendanceApi,
  departmentApi,
  roleApi
}
